package com.boco.wmworkflow.common.xmlmodel;

import java.util.*;
import com.boco.webmaster.common.xsdmap.workflow.wfstate.*;
import com.boco.webmaster.common.xsdmap.workflow.wfcfg.*;

public class WfStateXmlModelFactory {
    private static WfStateXmlModelFactory instance;
    private Map wfStateModelTable = new HashMap();


    public static WfStateXmlModelFactory createInstance(WfCfgType[] wfCfgs) throws Exception{
        if(instance == null){
            instance = new WfStateXmlModelFactory(wfCfgs);
        }
        return instance;
    }

    public static WfStateXmlModelFactory getInstance(){
        return instance;
    }

    private WfStateXmlModelFactory(WfCfgType[] wfCfgs)  throws Exception{
        for(int i=0; i<wfCfgs.length; i++){
            String stateFileName = wfCfgs[i].getStateFilename();
            WfStateXmlModel stateModel = new WfStateXmlModel("xmlmodel/" + stateFileName);
            wfStateModelTable.put(wfCfgs[i].getProcessId(), stateModel);
        }
    }

    public WfStateXmlModel getStateModel(String processId){
        return (WfStateXmlModel) wfStateModelTable.get(processId);
    }
}
